/*
 *  txdnet.cn tonydon
 * 
 */
package cn.txdnet.txcms.dao;

import cn.txdnet.txcms.domain.Events;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.mapper.EventsMapper;
import cn.txdnet.txcms.query.EventsQuery;
import cn.txdnet.txcms.query.ViewEventsQuery;
import cn.txdnet.txweb.utils.CollectionUtil;
import java.util.List;
import java.util.Map;

/**
 * 事件活动DAO
 *
 * @author txdnet
 */
public class EventsDAO extends MybatisBaseDAO {

    /**
     * 新增活动
     *
     * @param event
     * @return
     */
    public int insertEvents(Events event) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.insertEvents(event);
    }

    /**
     * 更新活动信息
     *
     * @param event
     * @return
     */
    public int updateEvents(Events event) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.updateEvents(event);
    }

    /**
     * 删除活动
     *
     * @param ida
     * @return
     */
    public int deleteEvents(int[] ida) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.deleteEvents(ida);
    }

    /**
     * 更新发布状态
     *
     * @param m
     * @return
     */
    public int updatePubstate(Map<String, Object> m) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.updatePubstate(m);
    }

    /**
     * 更新板块类别
     *
     * @param m
     * @return
     */
    public int updateChannelAndCatalog(Map<String, Object> m) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.updateChannelAndCatalog(m);
    }

    /**
     * 更新发布时间
     *
     * @param m
     * @return
     */
    public int updatePubTime(Map<String, Object> m) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.updatePubTime(m);
    }

    /**
     * 更新截止时间
     *
     * @param m
     * @return
     */
    public int updateEndTime(Map<String, Object> m) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.updateEndTime(m);
    }

    /**
     * 累加信息查看次数
     *
     * @param id
     * @return
     */
    public int increaseHitNum(int id) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.increaseHitNum(id);
    }

    /**
     * 查询记录
     *
     * @param query
     * @return
     */
    public PageDTO queryByFactor(EventsQuery query) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        query.filter();
        List list = mapper.listByFactor(query);
        if (query.getRownum().intValue() == 0 && CollectionUtil.isNotEmpty(list)) {
            query.setRownum(mapper.countByFactor(query));
        }
        return new PageDTO(list, query.getRownum());
    }

    /**
     * 查询记录用于编辑表单
     *
     * @param id
     * @return
     */
    public Events queryEventsForEdit(int id) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.queryEventsForEdit(id);
    }

    /**
     * 前端活动查询详情
     *
     * @param ViewEventsQuery
     * @return
     */
    public Events queryEventsForView(ViewEventsQuery query) {
        EventsMapper mapper = this.getMapper(EventsMapper.class);
        return mapper.queryEventsForView(query);
    }
}
